package de.ars.client.items;

import java.util.Vector;



import de.ars.client.animator.IAnimationEventListener;
import de.ars.client.camera.picture;
import de.ars.client.datahandling.PropertyReader;
import de.ars.client.items.animators.ImportPictureManagerAnimator;
import de.ars.client.items.elements.ListItem;
import de.ars.client.paintSystems.StringPainter;
import de.ars.client.screens.MainScreen;

public class ImportPictureManager extends AbstractSlideItem
{
	private int statePressed;
	
	private static final int STATE_CANCEL = 0;
	private static final int STATE_LOAD_PICTURE = 1;
	
	public ImportPictureManager(int _width, int _height, MainScreen _parent, StringPainter _stringPainter)
	{
		super(_width,_height,_parent,_stringPainter);

    	this.animator = new ImportPictureManagerAnimator(this);
    	this.animator.createNewAnimationPoint(this.layout.getEditClosePos());
        this.animator.createNewAnimationPoint(this.layout.getEditCloseSize());
        this.animator.createNewAnimationPoint(this.layout.getEditCloseTextPos());
        this.animator.setLayout(this.layout);
        
        this.entryItems = new Vector();
    	this.entryItems.addElement(new ListItem(this.stringPainter, PropertyReader.getProperty("import.filesystem"), "import.filesystem"));
    	this.entryItems.addElement(new ListItem(this.stringPainter, PropertyReader.getProperty("import.camera"), "import.camera"));
    	statePressed = STATE_CANCEL;
	}
	
	
	public boolean keyPressed(int _key)
	{
		if (isOpen())
			if (!super.keyPressed(_key))
			{
				switch(_key)
				{
				case -5:
					statePressed = STATE_LOAD_PICTURE;
					close();
					return true;
				case -6:
					statePressed = STATE_CANCEL;
					close();
					return true;
				}
			}
			else
				return true;
		return false;
	}
	
	public void animationEvent(int event) 
	{
		super.animationEvent(event);
		if( event == IAnimationEventListener.ANIMATION_STOPPED )
        {
			if (statePressed == STATE_LOAD_PICTURE)
			{
	    		switch(this.selectedItemIndex)
	    		{
	    			case 0:
	    				parent.openPNGBrowser();
	    			break;
	    			case 1:
	    				picture.showCamera();
	    			break;
	    		}
	    		statePressed = STATE_CANCEL;
			}
        }
	}
}